package leetcodecompetition.S121;

import org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * @Author: Siantar
 * @Date: 2024-01-06-22:31
 * @Description: 1.0
 */
public class T100157 {
    public int missingInteger(int[] nums) {
        int n = nums.length;
        int sum = nums[0];
        for (int i = 1; i < n; i++) {
            if (nums[i] != nums[i - 1] + 1) {
                break;
            }
            sum += nums[i];
        }
        Arrays.sort(nums);
        int res = nums[0];
        for (int num : nums) {
            System.out.println(num);
            if (res >= num) {
                res = Math.max(num + 1, sum);
            } else break;
        }
        return res;
    }

    @Test
    public void test() {
        System.out.println(missingInteger(new int[]{3, 4, 5, 1, 12, 14, 13}));
    }
}
